package com.request; /**
 * @author wzm
 * @create 2023-03-06 9:45
 */

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/rs01")
public class RequestServlet01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       //get请求
        //1.request.getMethod()获取请求的方式
        String method = request.getMethod();
        System.out.println("method = " + method);//GET

        //2.request.getContextPath();获取项目的虚拟目录 （当前项目路径）
        String contextPath = request.getContextPath();
        System.out.println("contextPath = " + contextPath);// /javaweb06

        //3. request.getRequestURL() 获取URL(统一资源定位符)
        StringBuffer requestURL = request.getRequestURL();
        System.out.println("requestURL.toString() = " + requestURL.toString());

        //4.request.getRequestURI(); 获取URI(统一资源标识符)
        String requestURI = request.getRequestURI();
        System.out.println("requestURI = " + requestURI);

        //5.request.getQueryString() 获取Get请求的参数
        String queryString = request.getQueryString();
        System.out.println("queryString = " + queryString);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
